package com.sdwl.imchat.util;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * 统一接口返回参数
 * @author longyubo
 * @since 2020-03-02
 */
@Getter
@Setter
@NoArgsConstructor
public class ApiResult implements Serializable{
	
	private static final long serialVersionUID = 1L;

	private static final Integer ERROR=500;
	private static final Integer SUCCESS=200;

	/**
	 * 返回代码值
	 */
	private Integer code;
	/**
	 * 返回提示的消息
	 */
	private String msg;
	/**
	 * 定义返回的参数
	 */
	private Object data;

	public ApiResult(Integer code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	public ApiResult(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static ApiResult success(){
		return new ApiResult(SUCCESS, "success",null);
	}
	public static ApiResult success(Object data){
		return new ApiResult(SUCCESS, "success",data);
	}
	public static ApiResult success(String msg){
		return new ApiResult(SUCCESS, msg);
	}
	public static ApiResult success(String msg,Object data){
		return new ApiResult(SUCCESS, msg,data);
	}
	public static ApiResult success(Integer code,String msg,Object data){
		return new ApiResult(code, msg,data);
	}
	public static ApiResult error(){
		return new ApiResult(ERROR, "error",null);
	}
	public static ApiResult error(String msg,Object data){
		return new ApiResult(ERROR, msg,data);
	}
	public static ApiResult error(Object data){
		return new ApiResult(ERROR, "error",data);
	}
	public static ApiResult error(String msg){
		return new ApiResult(ERROR, msg);
	}
	public static ApiResult error(Integer code,String msg,Object data){
		return new ApiResult(code, msg,data);
	}

	@Override
	public String toString() {
		return "ApiResult{" +
				"code='" + code + '\'' +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}
}
